package com.ymatou.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.LiveRoomInfo;
import com.ymatou.iapi.livebuyer.parameter.QueryLiveReplayBean;
import com.ymatou.iapi.livebuyer.service.QueryLiveReplayCall;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.DesUtil;
import com.ymttest.utils.YMTDateUtil;
/**
*查询直播回放
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryLiveReplay{
	private static QueryLiveReplayBean querylivereplayBean;
	private static QueryLiveReplayCall querylivereplayCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询直播回放");
	}

	@Before
	public void caseUp() {
		querylivereplayBean=new QueryLiveReplayBean();
		querylivereplayCall=new QueryLiveReplayCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querylivereplayCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(LiveRoomInfo liveRoomInfo,boolean hasHistoryUrl) throws Exception {
		LiveRoom liveroom = new LiveRoomWapper().selectLiveRoomById(liveRoomInfo.getLiveId());
		Logger.verifyEquals(liveroom.getGroupId(), liveRoomInfo.getGroupId(), "验证GroupId");
		if(hasHistoryUrl){
			String historyPlayUrl=DesUtil.encrypt(liveroom.getHistoryPlayUrl(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
			Logger.verifyEquals(historyPlayUrl, liveRoomInfo.getHistoryPlayUrl(), "验证HistoryPlayUrl");
		}else{
			Logger.verifyIsNull(liveRoomInfo.getHistoryPlayUrl(), "验证HistoryPlayUrl");
		}
		Logger.verifyEquals(liveroom.getId(), liveRoomInfo.getLiveId(), "验证LiveId");

		Logger.verifyEquals(liveroom.getLiveTitle(), liveRoomInfo.getLiveTitle(), "验证LiveTitle");
		if (liveRoomInfo.getPreVideo() != null) {
			Logger.verifyEquals(liveroom.getPreVideoHeight(), liveRoomInfo.getPreVideo().getPreVideoHeight(), "验证getPreVideoHeight");
			Logger.verifyEquals(liveroom.getPreVideoLength(), liveRoomInfo.getPreVideo().getPreVideoLength(), "验证getPreVideoLength");
			Logger.verifyEquals(liveroom.getPreVideoUrl(), liveRoomInfo.getPreVideo().getPreVideoUrl(), "验证getPreVideoUrl");
			Logger.verifyEquals(liveroom.getPreVideoWidth(), liveRoomInfo.getPreVideo().getPreVideoWidth(), "验证getPreVideoWidth");
		}
		Logger.verifyEquals(liveroom.getUserId(), liveRoomInfo.getUserId(), "验证UserId");
		Logger.verifyEquals(liveroom.getLiveDesc(), liveRoomInfo.getLiveDesc(), "验证LiveDesc");
		Logger.verifyEquals(liveroom.getPutawayCount(), liveRoomInfo.getPutawayCount(), "验证PutawayCount");
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryLiveReplay_001() {
		Logger.start(true,"查询直播回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			LiveRoomCallService.enterGroup(createlive.getId(), 1);
			LiveRoomCallService.getLikeCount(createlive.getId(), 1, 2);
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			querylivereplayBean.setLiveId(createlive.getId());
			querylivereplayCall.setData(querylivereplayBean);
			querylivereplayCall.callService();			
			Logger.verifyEquals("200", querylivereplayCall.getString("code"), "判断code是否为200");
			Logger.debug(FormatUtil.beanToGSONString(querylivereplayCall.getLiveRoomInfo()));
			//{"liveId":3913,"userId":1171107,"groupId":"1512617124151","historyPlayUrl":"http://1255315550.vod2.myqcloud.com/1255315550_498217985245814436165887373/playlist.m3u8","liveTitle":"直播标题648356219760193400","viewNum":121,"onLineNum":1,"likeNum":0,"putawayCount":0}
			verifyDB(querylivereplayCall.getLiveRoomInfo(),true);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QueryLiveReplay_002() {
		Logger.start(true,"不输入livieid查询直播回放失败");
		try {
//			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
//			LiveRoomCallService.enterGroup(createlive.getId(), 1);
//			LiveRoomCallService.getLikeCount(createlive.getId(), 1, 2);
//			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
//			LiveRoomCallService.LiveNotify(recivenotifyBean);
//			querylivereplayBean.setLiveId(createlive.getId());
			querylivereplayCall.setData(querylivereplayBean);
			querylivereplayCall.callService();			
			Logger.verifyEquals("100", querylivereplayCall.getString("code"), "判断code是否为200");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryLiveReplay_003() {
		Logger.start(true,"尚未生成回放信息,查询结果空");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			LiveRoomCallService.enterGroup(createlive.getId(), 1);
			LiveRoomCallService.getLikeCount(createlive.getId(), 1, 2);
//			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
//			LiveRoomCallService.LiveNotify(recivenotifyBean);
			querylivereplayBean.setLiveId(createlive.getId());
			querylivereplayCall.setData(querylivereplayBean);
			querylivereplayCall.callService();			
			Logger.verifyEquals("200", querylivereplayCall.getString("code"), "判断code是否为200");
			Logger.debug(FormatUtil.beanToGSONString(querylivereplayCall.getLiveRoomInfo()));
			verifyDB(querylivereplayCall.getLiveRoomInfo(),false);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QueryLiveReplay_004() {
		Logger.start(true,"输入错误livieid查询直播回放失败");
		try {
			querylivereplayBean.setLiveId(-100);
			querylivereplayCall.setData(querylivereplayBean);
			querylivereplayCall.callService();			
			Logger.verifyEquals("100", querylivereplayCall.getString("code"), "判断code是否为200");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}